import XMLParser
import unittest
import xmlTestData

class TestXMLParser(unittest.TestCase):

    def setUp(self):
        self.xml_parser = XMLParser.XMLParser()

    def test_artist_search(self):
        print "Testing artist search..."
        test_xml = xmlTestData.artist_search_xml
        expected_result = {'query': 'Metallica', 'artists': [{'url': 'http://www.last.fm/music/Metallica', 'image': 'http://userserve-ak.last.fm/serve/34/8906915.jpg', 'name': 'Metallica'}]}
        self.assertTrue(expected_result, self.xml_parser.parse_artist_search(test_xml))
        
    def test_song_search(self):
        print "Testing song search..."
        test_xml = xmlTestData.song_search_xml
        expected_result = {'query': 'Metallica', 'tracks': [{'url': 'http://www.last.fm/music/Metallica/_/Nothing+Else+Matters', 'listeners': '714539', 'name': 'Nothing Else Matters', 'artist': 'Metallica'}]}
        self.assertTrue(expected_result, self.xml_parser.parse_song_search(test_xml))
        
    def test_artist_info(self):
        print "Testing artist info..."
        test_xml = xmlTestData.artist_info_xml
        expected_result = {'plays': u'177751496', 'name': u'Metallica', 'url': u'http://www.last.fm/music/Metallica', 'image': u'http://userserve-ak.last.fm/serve/64/8906915.jpg', 'listeners': u'1989176', 'similar': [{'url': u'http://www.last.fm/music/Megadeth', 'name': u'Megadeth'}, {'url': u'http://www.last.fm/music/Slayer', 'name': u'Slayer'}, {'url': u'http://www.last.fm/music/Anthrax', 'name': u'Anthrax'}, {'url': u'http://www.last.fm/music/Iron+Maiden', 'name': u'Iron Maiden'}, {'url': u'http://www.last.fm/music/Pantera', 'name': u'Pantera'}]}
        self.assertTrue(expected_result, self.xml_parser.parse_artist_info(test_xml))
        
    def test_artist_similar(self):
        print "Testing similar artists..."
        test_xml = xmlTestData.artist_similar_xml
        expected_result = {'artist': [{'name': 'Thomas Bangalter', 'match': '1'}]}
        self.assertTrue(expected_result, self.xml_parser.parse_get_similar(test_xml))
        
    
    